<?php
namespace common\modules\favorite;

class ModuleInfo extends \common\core\modularity\ModuleInfo
{
    public function init()
    {
        parent::init();

        $this->id = 'favorite';
        $this->name = '收藏';
        $this->description = '收藏模块';
        $this->version = '1.0.0';
        $this->icon = '<i class="fa fa-dashboard"></i>';
        $this->has_backend = false;
        $this->has_frontend = false;
        $this->has_api = false;

        $this->is_system = false;

        $this->requireModules = 'user';
    }
    
    public function install()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        }
    
        $this->createTable('{{%favorite}}', [
            'id' => $this->primaryKey(),
            'user_id' => $this->integer()
            ->notNull(),
            'object_type' => $this->integer()
            ->notNull(),
            'object_id' => $this->integer()
            ->notNull(),
            'created_at' => $this->integer()
        ], $tableOptions);
    
        $this->addForeignKey('fk_favorite_user', '{{%favorite}}', 'user_id', '{{%user}}', 'id', 'cascade', 'cascade');
    }
    
    public function uninstall()
    {
        $this->dropForeignKey('fk_favorite_user', '{{%favorite}}');
        $this->dropTable('{{%favorite}}');
    }
}